import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:largefriends/pages/lf_payment/lf_payment_logic.dart';
import 'package:largefriends/res.dart';
import 'package:largefriends/res/lf_color.dart';
import 'package:largefriends/res/lf_double_ext.dart';
import 'package:largefriends/res/lf_fonts.dart';
import 'package:largefriends/res/lf_text_style.dart';
import 'package:largefriends/res/strings/lf_strings.dart';
import 'package:largefriends/utils/lf_scroll_behavior.dart';
import 'package:largefriends/widgets/lf_app_bar.dart';

import '../../res/lf_widget_ext.dart';
import 'lf_visibility_logic.dart';

class LfVisibilityPage extends StatefulWidget {
  const LfVisibilityPage({super.key});

  @override
  State<LfVisibilityPage> createState() => _LfVisibilityPageState();
}

class _LfVisibilityPageState extends State<LfVisibilityPage> {
  final logic = Get.put(LfVisibilityLogic());

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: Scaffold(
          appBar: lfAppBar(
              leadingCallback: () {
                Get.back();
              },
              title: strPrivacyAndVisibility.tr),
          body: ScrollConfiguration(
            behavior: LfScrollBehavior(),
            child: CustomScrollView(
              slivers: [
                20.h.sliverBox,
                Row(
                  children: [
                    16.w.sbw,
                    Flexible(
                        child: Text(
                      strProfilePrivacy.tr,
                      style: lfTextStyle(sp: 17.sp, fontFamily: fontMedium,color: color514F62),
                    )),
                    5.w.sbw,
                    logic.userEntity.isGold()
                        ? empty
                        : Image.asset(
                            Res.icon_premium,
                            width: 24.r,
                            color: colorFF007F,
                          )
                  ],
                ).sliverBox,
                10.h.sliverBox,
                Obx(() => item(
                    content: strHideMeFromAllMembers.tr,
                    open: logic.hide.value == 1,
                    click: () {
                      if (logic.userEntity.isGold() == false) {
                        toPayment();
                        return;
                      }
                      logic.changeHidden(
                          logic.hide.value == 1 ? 0 : 1, 'hidden_all');
                    })).sliverBox,
                tips(content: strOtherMembersCantSee.tr).sliverBox,
                Obx(() => item(
                    content: strHideMeFromWomen.tr,
                    open: logic.hideGender.value == 1,
                    click: () {
                      if (logic.userEntity.isGold() == false) {
                        toPayment();
                        return;
                      }
                      logic.changeHiddenGender(
                          logic.hideGender.value == 1 ? 0 : 1);
                    })).sliverBox,
                Obx(() => item(
                    content: strHideMeFromMen.tr,
                    open: logic.hideGender.value == 2,
                    click: () {
                      if (logic.userEntity.isGold() == false) {
                        toPayment();
                        return;
                      }
                      logic.changeHiddenGender(
                          logic.hideGender.value == 2 ? 0 : 2);
                    })).sliverBox,
                Obx(() => item(
                    content: strShowOnlyLike.tr,
                    open: logic.hide.value == 3,
                    click: () {
                      if (logic.userEntity.isGold() == false) {
                        toPayment();
                        return;
                      }
                      logic.changeHidden(
                          logic.hide.value == 3 ? 0 : 3, 'hidden_except_liked');
                    })).sliverBox,
                Obx(() => item(
                    content: strShowOnlyLikeAndPremium.tr,
                    open: logic.hide.value == 4,
                    click: () {
                      if (logic.userEntity.isGold() == false) {
                        toPayment();
                        return;
                      }
                      logic.changeHidden(
                          logic.hide.value == 4 ? 0 : 4, 'hidden_except_liked');
                    })).sliverBox,
                30.h.sliverBox,
                Row(
                  children: [
                    16.w.sbw,
                    Flexible(
                        child: Text(
                      strActivityPrivacy.tr,
                      style: lfTextStyle(sp: 17.sp, fontFamily: fontBold,color: color514F62),
                    )),
                    logic.userEntity.isGold()
                        ? empty
                        : Image.asset(
                            Res.icon_premium,
                            width: 24.r,
                            color: colorFF007F,
                          )
                  ],
                ).sliverBox,
                10.h.sliverBox,
                Obx(() => item(
                    content: strBrowserProfileAnonymously.tr,
                    open: logic.hideView.value == 1,
                    click: () {
                      if (logic.userEntity.isGold() == false) {
                        toPayment();
                        return;
                      }
                      logic
                          .changeAnonymously(logic.hideView.value == 1 ? 0 : 1);
                    })).sliverBox,
                tips(content: strBrowserProfileTip.tr).sliverBox,
                Obx(() => item(
                    content: strHideMyOnlineStatus.tr,
                    open: logic.hideOnline.value == 1,
                    click: () {
                      if (logic.userEntity.isGold() == false) {
                        toPayment();
                        return;
                      }
                      logic.changeHiddenOnline(
                          logic.hideOnline.value == 1 ? 0 : 1);
                    })).sliverBox,
              ],
            ),
          ),
        ),
        onWillPop: () async {
          Get.back();
          return false;
        });
  }

  Widget item(
      {required String content, required bool open, required Function click}) {
    return InkWell(
      child: Row(
        children: [
          16.w.sbw,
          Expanded(
              child: Text(
            content,
            style: lfTextStyle(sp: 16.sp, fontFamily: fontRegular),
          )),
          Switch(
              value: open,
              onChanged: (value) {
                click.call();
              },activeColor: colorFF007F)
        ],
      ),
      onTap: () {
        click.call();
      },
    );
  }

  Widget tips({required String content}) {
    return Padding(
      padding: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 10.h),
      child: Text(
        content,
        style:
            lfTextStyle(sp: 13.sp, fontFamily: fontRegular, color: color514F62),
      ),
    );
  }
}
